package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.common.VMSystem;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VmStatusContract;
import com.lkd.emq.Topic;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author : Bing
 * @Date 2023/3/2 18:52
 */
@Component
@Topic(TopicConfig.VMS_STATUS_TOPIC)
public class AutoUpdateMainTainStatusHandler implements MsgHandler {

    @Autowired
    private VendingMachineService vendingMachineService;

    @Override
    public void process(String jsonMsg) throws IOException {

        //解析消息
        VmStatusContract statusContract = JsonUtil.getByJson(jsonMsg, VmStatusContract.class);


        //修改售货机状态
        if (statusContract.getInnerCode() != null && statusContract.getInnerCode() != ""){
            vendingMachineService.updateStatus(statusContract.getInnerCode(), VMSystem.VM_STATUS_REPAIR);
        }

    }

}
